package com.youpingou.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.youpingou.domain.SkuComment;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SkuCommentMapper extends BaseMapper<SkuComment> {

    @Select("select count(*) from tb_sku_comment where spu_id = #{spuId}")
    public Integer findCountBySpuId(Integer spuId);

    @Select("select avg(star) from tb_sku_comment where spu_id = #{spuId}")
    public Double findAvgStarBySpuId(Integer spuId);


    @Select("select * from tb_sku_comment where spu_id = #{spuId} order by created_at desc limit #{page},#{pagesize}")
    @Results({
            @Result(property = "user",column = "user_id",
                    one = @One(select = "com.youpingou.mapper.UserMapper.selectById")
            )
    })
    public List<SkuComment> findCommentsBySpuId(@Param("spuId") Integer spuId,@Param("page") Integer page,@Param("pagesize") Integer pagesize);
}
